package com.java.thread.synchroniz;
/**
 * 所谓同步就是在统一时间段中只有有一个线程运行<br/>
 * 
 * 
 * @author shazhengbo
 *
 */
public class SynchronizedThread implements Runnable {

	private int count = 15;

	@Override
	public void run() {
		for (int i = 0; i < 5; i++) {
			synchronized (this) {
				if (count > 0) {
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println(count--);
				}
			}
		}

	}
	
	public static void main(String[] args) {
		SynchronizedThread st=new SynchronizedThread();
		Thread t1=new Thread(st);
		Thread t2=new Thread(st);
		Thread t3=new Thread(st);
		t1.start();
		t2.start();
		t3.start();
		//对于单个信息没问题，但是过多的同步将会导致锁死
	}

}
